package com.javabi.htmlbuilder.css.selector;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.javabi.htmlbuilder.css.CSSBuilder;
import com.javabi.htmlbuilder.css.CSSSelector;

/**
 * A CSS Simple Selector
 */
public class SimpleSelector implements CSSSelector {

	/** The selector list. */
	private final List<String> selectorList = new ArrayList<String>();

	/**
	 * Creates a new selector family.
	 * @param name the selector name.
	 */
	public SimpleSelector(String name) {
		addSelector(name);
	}

	/**
	 * Creates a new selector family.
	 * @param names the selector names.
	 */
	public SimpleSelector(String... names) {
		addSelectors(names);
	}

	/**
	 * Creates a new selector family.
	 * @param names the selector names.
	 */
	public SimpleSelector(Collection<String> names) {
		addSelectors(names);
	}

	/**
	 * Add the named selector.
	 * @param name the selector name.
	 */
	public void addSelector(String name) {
		if (name.length() == 0) {
			throw new IllegalArgumentException("name is empty");
		}
		selectorList.add(name);
	}

	/**
	 * Add the named selectors.
	 * @param names the selector names.
	 */
	public void addSelectors(String... names) {
		for (String name : names) {
			addSelector(name);
		}
	}

	/**
	 * Add the named selectors.
	 * @param names the selector names.
	 */
	public void addSelectors(Collection<String> names) {
		for (String name : names) {
			addSelector(name);
		}
	}

	/**
	 * Append this to the given css builder.
	 * @param css the css builder.
	 * @return the css builder.
	 */
	public CSSBuilder appendTo(CSSBuilder css) {
		css.names(selectorList);
		return css;
	}

}
